/*
 * MesoscopicTrafficSimulation.cpp
 *
 *  Created on: 12/10/2011
 *      Author: godinho
 */

#include <evolutive/impl/MesoscopicTrafficSimulation.h>
#include <evolutive/impl/MesoscopicNetworkBuilder.h>
#include <Network.h>
#include <SimulationNode.h>
#include <NodeSource.h>
#include <Controller.h>
#include <localview/Phase.h>
#include <localview/Link.h>
#include <vector>
#include <math.h>
#include <defaults.h>

typedef MesoscopicTrafficSimulation::SimulationInterfaceImpl simulationInterfaceImpl;

MesoscopicTrafficSimulation::MesoscopicTrafficSimulation() {
	mSimulationInterface = new SimulationInterfaceImpl();
	mControler = 0;
}

MesoscopicTrafficSimulation::~MesoscopicTrafficSimulation() {
	delete mSimulationInterface;
}

void MesoscopicTrafficSimulation::simulate(std::vector<Case*> cases, localview::LocalView* lv, int timesteps) {
	for(unsigned int i = 0; i < cases.size(); i++) {
		simulateCase(cases[i], lv, timesteps);
	}
}

void MesoscopicTrafficSimulation::simulateCase(Case* c, localview::LocalView* lv, int timesteps) {
	if(mControler) {
		delete mControler;
	}

	Network* net = buildSimulationEnvironment(lv, c);
	mControler = new Controller(net);
	mControler->setOutput(mSimulationInterface);
	mControler->startSimulation(timesteps);
	delete net;
}

void MesoscopicTrafficSimulation::stopSimulation() {
	mControler->stopSimulation();
	mControler = 0;
}

Network* MesoscopicTrafficSimulation::buildSimulationEnvironment(localview::LocalView* lv, Case* c) {

	MesoscopicNetworkBuilder* netBuilder = new MesoscopicNetworkBuilder();

	Network* net = netBuilder->lvNetwork2Mesoscopic(lv->getNetwork());
	delete netBuilder;

	return net;
}

simulationInterfaceImpl::SimulationInterfaceImpl() {

}

simulationInterfaceImpl::~SimulationInterfaceImpl() {

}

void simulationInterfaceImpl::startStep(int step, Network* network) {

}

void simulationInterfaceImpl::endStep(int step, Network* network) {

}

void simulationInterfaceImpl::startSimulation(Network* network) {

}

void simulationInterfaceImpl::endSimulation(Network* network) {

}
